package com.wyx.httpService.jinyeService.impl;
//换一种思路获得  yytJessionID

import com.wyx.utils.jinyeUtil.JEncipherUtil;
import okhttp3.*;
import org.junit.Test;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class Login2 {
    public static String YYTJSESSIONID;
    public static String usercode = "140105122422";
    public static String pk_corp = "0001";
    public static String uiInfo = "uiversion=1.0.0@uipath=https://www.jinye.cn";
    public static String TGC;
    public static LoginServiceImpl loginService = new LoginServiceImpl();

    public static void main(String[] args) throws InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException {

        loginService.getCaptcha();
        loginService.getParam();
        loginService.validUser();
        String execution = loginService.execution;
        YYTJSESSIONID = execution.substring(0, 36);
        getTgc();
    }

    public static void getTgc() {
        OkHttpClient client = new OkHttpClient();
        RequestBody requestBody = new FormBody.Builder()
                .add("username", "140105122422")
                .add("yytpasspword", "")
                .add("password", JEncipherUtil.urlEncode(loginService.encipherPassword))
                .add("execution", JEncipherUtil.urlEncode(loginService.execution))
                .add("loginBeforeEnableSetPkcorp", "true")
                .add("_eventId", "submit")
                .add("geolocation", "")
                .add("md5pwd", JEncipherUtil.urlEncode(loginService.encipherPassword))
                .add("csrfToken_t", JEncipherUtil.urlEncode(loginService.csrfToken_t))
                .add("isNeedVerifyCode", "true")
                .add("captcha", loginService.captcha)
                .add("token", loginService.token)
                .add("defaultPkCorp", "0")
                .add("pk_corp", "0001")
                .add("cipherText", "")
                .add("plainText", "")
                .add("csrfToken", JEncipherUtil.urlEncode(loginService.csrfToken_t))
                .add("submit", JEncipherUtil.urlEncode("登录中..."))
                .build();
        String str = "username=140105122422&yytpasspword=&password=T4X3L3qN1T%2BN0v8UjDKvUw%3D%3D&execution=b0d7c3b3-d408-4e16-b358-e7bd80830b54_ZXlKaGJHY2lPaUpJVXpVeE1pSjkuRnhwcURDTnNF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pWUNVNkVmT01OaEhEdDQ1eWlZbFRJak1TVmI1ejcvSUJVKytyQVEvWWhuc3VUVHpmS2Y3bzY5bzFWMkRRPS5ZVTZVZ29JTURnNW1wWm1iU29wOVRFbllxUWJSSXlTZ0c3VzhRTUdwRVdRc3JpbXRTeWFsZWhSLUh5TWhTTlNxVVhEYWtzQnAyN3ZrU1NDUHpMWFJkUQ%3D%3D&loginBeforeEnableSetPkcorp=true&_eventId=submit&geolocation=&md5pwd=T4X3L3qN1T%2BN0v8UjDKvUw%3D%3D&csrfToken_t=F6XtH2LGA2%2Bp0wKwNGtmGHeTpZWKNa2vAIj6Pgjr258%3D&isNeedVerifyCode=true&captcha=W1H3&token=d992adf0d13b403493dd739791dfd473&defaultPkCorp=0&pk_corp=0001&cipherText=&plainText=&csrfToken=F6XtH2LGA2%2Bp0wKwNGtmGHeTpZWKNa2vAIj6Pgjr258%3D&submit=%E7%99%BB%E5%BD%95%E4%B8%AD...";
        FormBody formBody = (FormBody) requestBody;
        String[] split = str.split("&");
        for (int i = 0; i < formBody.size(); i++) {
            System.out.println("网页的" + split[i]);
            System.out.println("自己的" + formBody.name(i) + "=" + formBody.value(i));
            System.out.println("--");
        }
        Request request = new Request.Builder()
                .url("https://www.jinye.cn/cas/login?_t=" + loginService._t)
                .post(formBody)
                .header("Cookie", "SESSION=" + loginService.session)
                .header("uiInfo", uiInfo)
                .header("pk_corp", pk_corp)
                .header("usercode", usercode)
                .header("YYTJSESSIONID", YYTJSESSIONID)
                .build();

        try {
            // 发送请求并获取响应
            Response response = client.newCall(request).execute();
            if (response.isSuccessful() && response.body() != null) {
//                TODO: 在这儿 返回值为空
                System.out.println(response.headers().toString());
                String set_cookie = response.header("Set-Cookie");
                System.out.println(set_cookie);
            } else {
                System.out.println("Request failed");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
